***********************************************************************************************
*                        PLOT HETEROGENEITY COEFFS BY HOSPITAL CHARACTERISTIC                 *
* Last updated: 3/23/2023																	  *
***********************************************************************************************


log using "${SIDCodePath}/sidsedd_regressions_trad_hetero_plot.log", replace

use "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_app_contracted_136_diRD.dta", clear
replace var = "has med. necc. software" if var == "1.post_qtr_after_MN#1.app_contracted_136"
keep if var == "has med. necc. software"


preserve

	use "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_above_avg_beds_diRD.dta", clear
	replace var = "above avg beds" if var == "1.post_qtr_after_MN#1.above_avg_beds"
	keep if var == "above avg beds"
	tempfile temp
	save `temp'
restore
append using `temp'



preserve
	use "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_urban_diRD.dta", clear
	replace var = "urban" if var == "1.post_qtr_after_MN#1.urban"
	keep if var == "urban"
	tempfile temp
	save `temp'
restore

append using `temp'

preserve
	use "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_teaching_diRD.dta", clear
	replace var = "teaching" if var == "1.post_qtr_after_MN#1.teaching"
	keep if var == "teaching"
	tempfile temp
	save `temp'
restore

append using `temp'


preserve
	use "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_hospprofittype_diRD.dta", clear
	replace var = "for-profit" if var == "1.post_qtr_after_MN#2.hospprofittype"
	replace var = "gov't" if var == "1.post_qtr_after_MN#3.hospprofittype"
	keep if var == "non-profit" | var == "gov't" | var == "for-profit"
	tempfile temp
	save `temp'
restore
append using `temp'



gen n = _n

label define coeflabel  1 "med. necc. software" 2 "above avg beds" 3 "urban" 4 "teaching" 5 "for-profit" 6 "gov't"
label values n coeflabel

gen min = coef - 1.96*stderr
gen max = coef + 1.96*stderr


twoway (scatter n coef) (rcap min max n, horizontal), ///
	graphregion(color(white)) xline(0, lcolor(black) lpattern(dash)) ///
	ylabel(1 "med. necc. software" 2 "above avg beds" 3 "urban" 4 "teaching" 5 "for-profit" 6 "gov't", angle(360)) ///
	legend(off) ytitle("") xtitle("Interaction with Post x AfterMN Coefficient")
graph export "${SIDOutputPath}/reg_trad_patientFEs/reg_med_hosphetero_3h_coeffplot.pdf", replace

log close